package com.itedge.solutionmanager.domain.dto;

import java.text.SimpleDateFormat;
import java.util.Locale;

import org.springframework.context.MessageSource;

import com.itedge.infrastructure.constants.InfrastructureConstants;
import com.itedge.solutionmanager.constants.SolutionManagerConstants;
import com.itedge.solutionmanager.domain.impl.Solution;

/**
 * Wrapper DTO (Data Transfer Object) around domain object 'Solution'
 */
public class SolutionDto {
	
	private Long id;
	private String name;
	private String customerName;
	private String phase;
	private String initialInfo;
	private String contactDate;
	
	/**
	 * Constructor of Wrapper class
	 * @param solution 
	 * @param currentLocale 
	 * @param currentLocale
	 */
	public SolutionDto(Solution solution, MessageSource messageSource,  Locale currentLocale) {
		
		this.id = solution.getId();
		this.name = solution.getName();
		this.customerName = solution.getCustomer() != null ? solution.getCustomer().getName() : null;
		if (messageSource != null) {
			this.phase = messageSource.getMessage(solution.getPhase().toString(), null, 
					InfrastructureConstants.UNDEFINED_MESSAGE, currentLocale);
		} else {
			this.phase = SolutionManagerConstants.UNDEFINED_MESSAGE_BUNDLE;
		}
		this.initialInfo = solution.getInitialInfo();
		
		SimpleDateFormat sdf = new SimpleDateFormat(InfrastructureConstants.ISO_DATE_TIME_FORMAT);
		
		this.contactDate = sdf.format(solution.getContactDate());
	}
	
	public Long getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public String getCustomerName() {
		return customerName;
	}

	public String getPhase() {
		return phase;
	}

	public String getInitialInfo() {
		return initialInfo;
	}
	
	public String getContactDate() {
		return contactDate;
	}
}
